﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tnelab.Wpf;

namespace Tnelab.WpfDemo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            BundledTheme bundledTheme = null;
            foreach (var rd in App.Current.Resources.MergedDictionaries)
            {
                if (rd is BundledTheme)
                {
                    bundledTheme = rd as BundledTheme;
                    break;
                }
            }
            if (bundledTheme == null)
            {
                return;
            }
            PColorPicker.SelectedBrush = new SolidColorBrush(bundledTheme.PrimaryColor.Value);
            RColorPicker.SelectedBrush = new SolidColorBrush(bundledTheme.RegionColor.Value);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Tnelab.Wpf.WindowEx.SetBlurable(this, false);
            Tnelab.Wpf.WindowEx.SetWindowChromeable(this, false);
        }

        private void ColorPicker_SelectedColorChanged(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
        {



            //ColorPicker.SelectedBrush.Color
        }

        private void PColorPicker_SelectedColorChanged(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
        {
            BundledTheme bundledTheme = null;
            foreach (var rd in App.Current.Resources.MergedDictionaries)
            {
                if (rd is BundledTheme)
                {
                    bundledTheme = rd as BundledTheme;
                    break;
                }
            }
            if (bundledTheme == null)
            {
                return;
            }
            bundledTheme.PrimaryColor = PColorPicker.SelectedBrush.Color;
            bundledTheme.TransparentColor = bundledTheme.TransparentColor;

            var rds = App.Current.Resources.MergedDictionaries;
            var nrd = new ResourceDictionary();
            nrd.Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Basic/Brushes.xaml");
            rds.Add(nrd);
        }

        private void RColorPicker_SelectedColorChanged(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
        {
            BundledTheme bundledTheme = null;
            foreach (var rd in App.Current.Resources.MergedDictionaries)
            {
                if (rd is BundledTheme)
                {
                    bundledTheme = rd as BundledTheme;
                    break;
                }
            }
            if (bundledTheme == null)
            {
                return;
            }
            bundledTheme.RegionColor = RColorPicker.SelectedBrush.Color;
            bundledTheme.TransparentColor = bundledTheme.TransparentColor;

            var rds = App.Current.Resources.MergedDictionaries;
            var nrd = new ResourceDictionary();
            nrd.Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Basic/Brushes.xaml");
            rds.Add(nrd);
        }
    }
}
